#include <iostream>
#include <string>
#include <cppunit/config/SourcePrefix.h>
#include "TestDesignExtractorWithPKB.h"

using namespace std;


void DesignExtractorWithPKBTest::setUp() {

}

void DesignExtractorWithPKBTest::tearDown() {

}

CPPUNIT_TEST_SUITE_REGISTRATION( DesignExtractorWithPKBTest );

void DesignExtractorWithPKBTest::testEnv1() {
	/* Environment 1:
	procedure p{
		x = y;             // 1
		while x {          // 2
			x = 1;         // 3
			y = 2;         // 4
			if y then {    // 5
				call q;}   // 6
			else {            
				call r;}}} // 7

	procedure q {
		x = 1;             // 8
		call r}            // 9

	procedure r {
		x = y;             // 10
		if x then {        // 11
			x = 1;}        // 12
		else {
			y = 1;}        // 13
		z = 1;             // 14
	}
	*/
	createEnv1();
	
	cout << "Testing Env1..." << endl;
	CPPUNIT_ASSERT(pkb->getProcName(0) == "");
	CPPUNIT_ASSERT(pkb->getProcIndex("p") == 1);
	CPPUNIT_ASSERT(pkb->getProcIndex("q") == 2);
	CPPUNIT_ASSERT(pkb->getProcIndex("r") == 3);
	CPPUNIT_ASSERT(pkb->getVarIndex("x") == 1);
	CPPUNIT_ASSERT(pkb->getVarIndex("y") == 2);
	CPPUNIT_ASSERT(pkb->getVarIndex("z") == 3);

}

void DesignExtractorWithPKBTest::testEnv2() {

	/* Environment 2
	procedure fifth5 {
		dog1 = cat2;						//1
		while dog1 {                		//2
			dog1 = bird3;          		//3
			while dog1 {           		//4
				dog1 = fish4; 			//5
				while dog1{				//6
					dog1 = can3;			//7
					while dog1{			//8
						dog1 = bird 2;	//9
					}
				}
			}
		} 
		while dog1 {                		//10
			dog1 = bird3;          		//11
			while dog1 {           		//12
				dog1 = fish4; 			//13
				while dog1{				//14
					dog1 = can3;			//15
					while dog1{			//16
						dog1 = bird 2;	//17
					}
				}
				while dog1{				//18
					dog1 = can3;			//19
					while dog1{			//20
						dog1 = bird 2;	//21
						if dog1 then{		//22
							dog1 = can3;	//23
						} else {
							dog1 = bird2;	//24
							if dog1 then {	//25
								dog1 = fish4	//26
							} else {
								dog1 = bird3;	//27
							}
						}
					}
				}
			}
		} 
		if dog1 then {							//28
			bird3 = bird2 ;						//29
		} else {
			while dog1 {							//30
				fish4 = bird2;					//31
			}
		}
		cat2 = can3;								//32
	}
	*/
	createEnv2();

	cout << "Testing Env2..." << endl;
	CPPUNIT_ASSERT(pkb->getProcName(0) == "");
	CPPUNIT_ASSERT(pkb->getProcIndex("fifth5") == 1);
	CPPUNIT_ASSERT(pkb->getVarIndex("dog1") == 1);
	CPPUNIT_ASSERT(pkb->getVarIndex("cat2") == 2);
	CPPUNIT_ASSERT(pkb->getVarIndex("bird3") == 3);
	CPPUNIT_ASSERT(pkb->getVarIndex("fish4") == 4);
	CPPUNIT_ASSERT(pkb->getVarIndex("can3") == 5);
	CPPUNIT_ASSERT(pkb->getVarIndex("bird2") == 6);
}

void DesignExtractorWithPKBTest::testEnv3() {
	createEnv3();
	
	cout << "Testing Env3..." << endl;
	CPPUNIT_ASSERT(pkb->getProcName(1) == "ifsource");
	CPPUNIT_ASSERT(pkb->getProcIndex("ifsource") == 1);
	CPPUNIT_ASSERT(pkb->getVarIndex("w") == 1);
	CPPUNIT_ASSERT(pkb->getVarIndex("x") == 2);
	CPPUNIT_ASSERT(pkb->getVarIndex("y") == 3);
	CPPUNIT_ASSERT(pkb->getVarIndex("z") == 4);
}

void DesignExtractorWithPKBTest::testEnv5() {
	/*
	procedure Charlie{
		i = 15;					// 1
		while i	{				// 2
			a = b;				// 3
			if x then {			// 4
				b = c;			// 5                  
				if c then {		// 6
					c = d; }	// 7
				else { 
					d = e; }}	// 8
			else{
				c = e; }		// 9
			while y {           // 10
				b = k; }        // 11
			b = z; }}          // 12
	*/
	createEnv5();
	
	cout << "Testing Env5..." << endl;
	CPPUNIT_ASSERT(pkb->getProcName(1) == "Charlie");
	CPPUNIT_ASSERT(pkb->getVarIndex("a") == 1);
	CPPUNIT_ASSERT(pkb->getVarIndex("b") == 2);
	CPPUNIT_ASSERT(pkb->getVarIndex("c") == 3);
	CPPUNIT_ASSERT(pkb->getVarIndex("d") == 4);
	CPPUNIT_ASSERT(pkb->getVarIndex("e") == 5);
	CPPUNIT_ASSERT(pkb->getVarIndex("i") == 6);
	CPPUNIT_ASSERT(pkb->getVarIndex("k") == 7);
	CPPUNIT_ASSERT(pkb->getVarIndex("x") == 8);
	CPPUNIT_ASSERT(pkb->getVarIndex("y") == 9);
	CPPUNIT_ASSERT(pkb->getVarIndex("z") == 10);
}

void DesignExtractorWithPKBTest::testEnv4() {

	/*
	procedure Fern {
		y = 10;				// 1
		x = y + 5;			// 2
		z = x * y + 4;		// 3
		v = x + z * 12;		// 4
		call Tulip;			// 5
		v = v + y + x;		// 6
		call Lily;			// 7
		t = v + y * x;		// 8
		while idx {				// 9
			t = x - z;			// 10
			if y then {			// 11
				z = z + y;		// 12
				idx = z + 1; }	// 13
			else {	
				x = z + y;			// 14 
				call Lily;			// 15
				idx = idx - 16; }	//16
			x = z + y; }		// 17
		call Orchid; }			// 18

	procedure Orchid {
		while idx {				// 19
			y = z*3 + 2*x;		// 20
			call Tulip;			// 21
			idx = idx - 1; }	// 22
		z = z + y + idx; }		// 23

	procedure Lily {
		while v {				// 24
			y = x + y; }		// 25
		x = y + x; }			// 26

	procedure Tulip {
		while t {				// 27
			if idx then {		// 28
				x = y + 80; }	// 29
			else {
				y = y * x + z + t * v; } } }	// 30
	*/
	createEnv4();
	
	cout << "Testing Env4..." << endl;
	CPPUNIT_ASSERT(pkb->getProcName(1) == "Fern");
	CPPUNIT_ASSERT(pkb->getProcIndex("Tulip") == 4);
	CPPUNIT_ASSERT(pkb->getVarIndex("idx") == 1);
	CPPUNIT_ASSERT(pkb->getVarIndex("t") == 2);
	CPPUNIT_ASSERT(pkb->getVarIndex("v") == 3);
	CPPUNIT_ASSERT(pkb->getVarIndex("x") == 4);
	CPPUNIT_ASSERT(pkb->getVarIndex("y") == 5);
	CPPUNIT_ASSERT(pkb->getVarIndex("z") == 6);
}

void DesignExtractorWithPKBTest::testUpdateProcUMStatus() {
	cout << "Testing updateProcUMStatus..." << endl;

	/////////////////////////
	// Test Environment #1 //
	/////////////////////////
	createEnv1();
	de->updateProcUMStatus();

	//------------
	//- POSITIVE -
	//------------
	CPPUNIT_ASSERT(pkb->isProcModifies(1, 1));
	CPPUNIT_ASSERT(pkb->isProcModifies(1, 2));
	CPPUNIT_ASSERT(pkb->isProcModifies(1, 3));
	CPPUNIT_ASSERT(pkb->isProcModifies(2, 1));
	CPPUNIT_ASSERT(pkb->isProcModifies(2, 2));
	CPPUNIT_ASSERT(pkb->isProcModifies(2, 3));
	CPPUNIT_ASSERT(pkb->isProcModifies(3, 1));
	CPPUNIT_ASSERT(pkb->isProcModifies(3, 2));
	CPPUNIT_ASSERT(pkb->isProcModifies(3, 3));

	CPPUNIT_ASSERT(pkb->isProcUses(1, 1));
	CPPUNIT_ASSERT(pkb->isProcUses(1, 2));
	CPPUNIT_ASSERT(pkb->isProcUses(2, 1));
	CPPUNIT_ASSERT(pkb->isProcUses(2, 2));
	CPPUNIT_ASSERT(pkb->isProcUses(3, 1));
	CPPUNIT_ASSERT(pkb->isProcUses(3, 2));

	//------------
	//- NEGATIVE -
	//------------
	CPPUNIT_ASSERT(!pkb->isProcUses(1, 3));
	CPPUNIT_ASSERT(!pkb->isProcUses(2, 3));
	CPPUNIT_ASSERT(!pkb->isProcUses(1, 3));


	/////////////////////////
	// Test Environment #2 //
	/////////////////////////
	createEnv2();

	de->updateProcUMStatus();

	//------------
	//- POSITIVE -
	//------------
	CPPUNIT_ASSERT(pkb->isProcModifies(1, 1));

	CPPUNIT_ASSERT(pkb->isProcUses(1, 1));
	CPPUNIT_ASSERT(pkb->isProcUses(1, 2));
	CPPUNIT_ASSERT(pkb->isProcUses(1, 3));
	CPPUNIT_ASSERT(pkb->isProcUses(1, 4));


	//------------
	//- NEGATIVE -
	//------------
	//CPPUNIT_ASSERT(!pkb->isProcModifies(1, 2));
	//CPPUNIT_ASSERT(!pkb->isProcModifies(1, 3));
	//CPPUNIT_ASSERT(!pkb->isProcModifies(1, 4));

	/////////////////////////
	// Test Environment #4 //
	/////////////////////////
	createEnv4();
	de->updateProcUMStatus();
}

void DesignExtractorWithPKBTest::testUpdateLineUMStatus() {
	cout << "Testing updateLineUMStatus..." << endl;

	/////////////////////////
	// Test Environment #1 //
	/////////////////////////
	createEnv1();
	de->updateProcUMStatus();
	de->updateLineUMStatus();
	
	//------------
	//- POSITIVE -
	//------------
	CPPUNIT_ASSERT(pkb->isLineModifies(2, 1));
	CPPUNIT_ASSERT(pkb->isLineModifies(2, 2));
	CPPUNIT_ASSERT(pkb->isLineModifies(2, 3));
	CPPUNIT_ASSERT(pkb->isLineModifies(3, 1));
	CPPUNIT_ASSERT(pkb->isLineModifies(5, 1));
	CPPUNIT_ASSERT(pkb->isLineModifies(5, 2));
	CPPUNIT_ASSERT(pkb->isLineModifies(5, 3));	
	CPPUNIT_ASSERT(pkb->isLineModifies(6, 1));
	CPPUNIT_ASSERT(pkb->isLineModifies(6, 2));
	CPPUNIT_ASSERT(pkb->isLineModifies(6, 3));
	CPPUNIT_ASSERT(pkb->isLineModifies(7, 1));
	CPPUNIT_ASSERT(pkb->isLineModifies(7, 2));
	CPPUNIT_ASSERT(pkb->isLineModifies(7, 3));
	CPPUNIT_ASSERT(pkb->isLineModifies(9, 1));
	CPPUNIT_ASSERT(pkb->isLineModifies(9, 2));
	CPPUNIT_ASSERT(pkb->isLineModifies(9, 3));
	CPPUNIT_ASSERT(pkb->isLineModifies(11, 1));
	CPPUNIT_ASSERT(pkb->isLineModifies(11, 2));

	CPPUNIT_ASSERT(pkb->isLineUses(2, 1));
	CPPUNIT_ASSERT(pkb->isLineUses(2, 2));
	CPPUNIT_ASSERT(pkb->isLineUses(5, 1));
	CPPUNIT_ASSERT(pkb->isLineUses(5, 2));
	CPPUNIT_ASSERT(pkb->isLineUses(6, 1));
	CPPUNIT_ASSERT(pkb->isLineUses(6, 2));
	CPPUNIT_ASSERT(pkb->isLineUses(7, 1));
	CPPUNIT_ASSERT(pkb->isLineUses(7, 2));
	CPPUNIT_ASSERT(pkb->isLineUses(9, 1));
	CPPUNIT_ASSERT(pkb->isLineUses(9, 2));
	CPPUNIT_ASSERT(pkb->isLineUses(11, 1));

	
	//------------
	//- NEGATIVE -
	//------------	
	CPPUNIT_ASSERT(!pkb->isLineModifies(11, 3));
	CPPUNIT_ASSERT(!pkb->isLineUses(2, 3));
	CPPUNIT_ASSERT(!pkb->isLineUses(5, 3));
	CPPUNIT_ASSERT(!pkb->isLineUses(6, 3));
	CPPUNIT_ASSERT(!pkb->isLineUses(7, 3));
	CPPUNIT_ASSERT(!pkb->isLineUses(9, 3));
	CPPUNIT_ASSERT(!pkb->isLineUses(11, 3));
	

	/////////////////////////
	// Test Environment #2 //
	/////////////////////////
	createEnv2();
	de->updateProcUMStatus();
	de->updateLineUMStatus();

	//------------
	//- POSITIVE -
	//------------
	CPPUNIT_ASSERT(pkb->isLineModifies(1, 1));
	CPPUNIT_ASSERT(pkb->isLineModifies(2, 1));
	CPPUNIT_ASSERT(pkb->isLineModifies(3, 1));
	CPPUNIT_ASSERT(pkb->isLineModifies(4, 1));
	CPPUNIT_ASSERT(pkb->isLineModifies(5, 1));
	
	CPPUNIT_ASSERT(pkb->isLineUses(1, 2));
	CPPUNIT_ASSERT(pkb->isLineUses(2, 1));
	CPPUNIT_ASSERT(pkb->isLineUses(2, 3));
	CPPUNIT_ASSERT(pkb->isLineUses(2, 4));
	CPPUNIT_ASSERT(pkb->isLineUses(3, 3));
	CPPUNIT_ASSERT(pkb->isLineUses(4, 1));
	CPPUNIT_ASSERT(pkb->isLineUses(4, 4));
	CPPUNIT_ASSERT(pkb->isLineUses(5, 4));


	//------------
	//- NEGATIVE -
	//------------
	CPPUNIT_ASSERT(!pkb->isLineModifies(1, 2));
	CPPUNIT_ASSERT(!pkb->isLineModifies(1, 3));
	CPPUNIT_ASSERT(!pkb->isLineModifies(1, 4));
	CPPUNIT_ASSERT(!pkb->isLineModifies(1, 5));
	CPPUNIT_ASSERT(!pkb->isLineModifies(2, 2));
	CPPUNIT_ASSERT(!pkb->isLineModifies(2, 3));
	CPPUNIT_ASSERT(!pkb->isLineModifies(2, 4));
	CPPUNIT_ASSERT(!pkb->isLineModifies(3, 2));
	CPPUNIT_ASSERT(!pkb->isLineModifies(3, 3));
	CPPUNIT_ASSERT(!pkb->isLineModifies(3, 4));
	CPPUNIT_ASSERT(!pkb->isLineModifies(4, 2));
	CPPUNIT_ASSERT(!pkb->isLineModifies(4, 3));
	CPPUNIT_ASSERT(!pkb->isLineModifies(4, 4));
	CPPUNIT_ASSERT(!pkb->isLineModifies(5, 2));
	CPPUNIT_ASSERT(!pkb->isLineModifies(5, 3));
	CPPUNIT_ASSERT(!pkb->isLineModifies(5, 4));

	CPPUNIT_ASSERT(!pkb->isLineUses(1, 1));
	CPPUNIT_ASSERT(!pkb->isLineUses(1, 3));
	CPPUNIT_ASSERT(!pkb->isLineUses(1, 4));
	CPPUNIT_ASSERT(!pkb->isLineUses(2, 2));
	CPPUNIT_ASSERT(!pkb->isLineUses(3, 1));
	CPPUNIT_ASSERT(!pkb->isLineUses(3, 2));
	CPPUNIT_ASSERT(!pkb->isLineUses(3, 4));
	CPPUNIT_ASSERT(!pkb->isLineUses(4, 2));
	CPPUNIT_ASSERT(!pkb->isLineUses(4, 3));
	CPPUNIT_ASSERT(!pkb->isLineUses(5, 1));
	CPPUNIT_ASSERT(!pkb->isLineUses(5, 2));
	CPPUNIT_ASSERT(!pkb->isLineUses(5, 3));

	/////////////////////////
	// Test Environment #4 //
	/////////////////////////
	createEnv4();
	de->updateProcUMStatus();
	de->updateLineUMStatus();

}

void DesignExtractorWithPKBTest::testUpdateNextStatus() {
	cout << "Testing updateNextStatus..." << endl;

	/////////////////////////
	// Test Environment #1 //
	/////////////////////////
	createEnv1();
	de->updateProcUMStatus();
	de->updateLineUMStatus();
	de->updateNextStatus();

	//------------
	//- POSITIVE -
	//------------
	CPPUNIT_ASSERT(pkb->isNext(1, 2));
	CPPUNIT_ASSERT(pkb->isNext(2, 3));
	CPPUNIT_ASSERT(pkb->isNext(3, 4));
	CPPUNIT_ASSERT(pkb->isNext(4, 5));
	CPPUNIT_ASSERT(pkb->isNext(5, 6));
	CPPUNIT_ASSERT(pkb->isNext(5, 7));
	CPPUNIT_ASSERT(pkb->isNext(6, 2));
	CPPUNIT_ASSERT(pkb->isNext(7, 2));
	CPPUNIT_ASSERT(pkb->isNext(8, 9));
	CPPUNIT_ASSERT(pkb->isNext(10, 11));
	CPPUNIT_ASSERT(pkb->isNext(11, 12));
	CPPUNIT_ASSERT(pkb->isNext(11, 13));
	CPPUNIT_ASSERT(pkb->isNext(12, 14));
	CPPUNIT_ASSERT(pkb->isNext(13, 14));

	//------------
	//- NEGATIVE -
	//------------
	CPPUNIT_ASSERT(!pkb->isNext(1, 3));
	CPPUNIT_ASSERT(!pkb->isNext(3, 1));
	CPPUNIT_ASSERT(!pkb->isNext(7, 8));
	CPPUNIT_ASSERT(!pkb->isNext(9, 10));
	CPPUNIT_ASSERT(!pkb->isNext(6, 5));
	CPPUNIT_ASSERT(!pkb->isNext(7, 5));
	CPPUNIT_ASSERT(!pkb->isNext(10, 12));
	CPPUNIT_ASSERT(!pkb->isNext(12, 11));
	CPPUNIT_ASSERT(!pkb->isNext(13, 11));


	/////////////////////////
	// Test Environment #3 //
	/////////////////////////
	createEnv3();
	de->updateProcUMStatus();
	de->updateLineUMStatus();
	de->updateNextStatus();

	//------------
	//- POSITIVE -
	//------------
	CPPUNIT_ASSERT(pkb->isNext(1, 2));
	CPPUNIT_ASSERT(pkb->isNext(1, 5));
	CPPUNIT_ASSERT(pkb->isNext(2, 3));
	CPPUNIT_ASSERT(pkb->isNext(2, 4));
	CPPUNIT_ASSERT(pkb->isNext(3, 6));
	CPPUNIT_ASSERT(pkb->isNext(4, 6));
	CPPUNIT_ASSERT(pkb->isNext(5, 6));
	CPPUNIT_ASSERT(pkb->isNext(6, 7));
	CPPUNIT_ASSERT(pkb->isNext(7, 6));
	CPPUNIT_ASSERT(pkb->isNext(6, 8));
	CPPUNIT_ASSERT(pkb->isNext(9, 10));
	CPPUNIT_ASSERT(pkb->isNext(10, 11));
	CPPUNIT_ASSERT(pkb->isNext(11, 10));
	CPPUNIT_ASSERT(pkb->isNext(10, 14));
	CPPUNIT_ASSERT(pkb->isNext(9, 12));
	CPPUNIT_ASSERT(pkb->isNext(12, 13));
	CPPUNIT_ASSERT(pkb->isNext(13, 12));
	CPPUNIT_ASSERT(pkb->isNext(12, 14));

	//------------
	//- NEGATIVE -
	//------------
	CPPUNIT_ASSERT(!pkb->isNext(1, 3));
	CPPUNIT_ASSERT(!pkb->isNext(1, 4));
	CPPUNIT_ASSERT(!pkb->isNext(6, 5));
	CPPUNIT_ASSERT(!pkb->isNext(15, 16));


	/////////////////////////
	// Test Environment #4 //
	/////////////////////////
	createEnv4();
	de->updateProcUMStatus();
	de->updateLineUMStatus();
	de->updateNextStatus();
}

void DesignExtractorWithPKBTest::testUpdateStarRelations() {
	cout << "Testing updateNextStatus..." << endl;

	/////////////////////////
	// Test Environment #1 //
	/////////////////////////
	createEnv1();
	de->updateProcUMStatus();
	de->updateLineUMStatus();
	de->updateNextStatus();
	de->updateStarRelations();
}

void DesignExtractorWithPKBTest::testUpdateNextLastModified() {
	cout << "Testing updateNextLastModified..." << endl;

	/////////////////////////
	// Test Environment #1 //
	/////////////////////////
	/*createEnv1();
	de->updateProcUMStatus();
	de->updateLineUMStatus();
	de->updateNextStatus();
	*/
	/////////////////////////
	// Test Environment #4 //
	/////////////////////////
	createEnv2();
	de->updateProcUMStatus();
	de->updateLineUMStatus();
	de->updateNextStatus();

	vector<vector<Type::Index::Line>> table;
	table = de->getLastModifiedTable();
	cout << "\nlastModifedTable of " << table.size() << " by " 
		<< table[1].size() << ":\n";
	de->printLastNextTable(table);

	table = de->getNextModifiedTable();
	cout << "\nnextModifedTable of " << table.size() << " by " 
		<< table[1].size() << ":\n";
	de->printLastNextTable(table);
	
}

void DesignExtractorWithPKBTest::testUpdateNextBipStatus() {
	/////////////////////////
	// Test Environment #1 //
	/////////////////////////
	createEnv1();
	de->run();
	de->setExitPointsOfProcs();
	de->updateNextBipStatus();

	//------------
	//- POSITIVE -
	//------------
	CPPUNIT_ASSERT(pkb->isNextBip(1, 2));
	CPPUNIT_ASSERT(pkb->isNextBip(2, 3));
	CPPUNIT_ASSERT(pkb->isNextBip(3, 4));
	CPPUNIT_ASSERT(pkb->isNextBip(4, 5));
	CPPUNIT_ASSERT(pkb->isNextBip(5, 6));

	CPPUNIT_ASSERT(pkb->isNextBip(6, 8));
	CPPUNIT_ASSERT(pkb->isNextBip(8, 9));
	CPPUNIT_ASSERT(pkb->isNextBip(9, 10));

	CPPUNIT_ASSERT(pkb->isNextBip(10, 11));
	CPPUNIT_ASSERT(pkb->isNextBip(11, 12));
	CPPUNIT_ASSERT(pkb->isNextBip(11, 13));
	CPPUNIT_ASSERT(pkb->isNextBip(12, 14));
	CPPUNIT_ASSERT(pkb->isNextBip(13, 14));
	CPPUNIT_ASSERT(pkb->isNextBip(14, 2));

	CPPUNIT_ASSERT(pkb->isNextBip(7, 10));

	//------------
	//- NEGATIVE -
	//------------
	CPPUNIT_ASSERT(!pkb->isNextBip(1, 3));
	CPPUNIT_ASSERT(!pkb->isNextBip(9, 2));
	CPPUNIT_ASSERT(!pkb->isNextBip(14, 9));
}

void DesignExtractorWithPKBTest::createEnv1() {
	/* Environment 1:
	procedure p{
		x = y;             // 1
		while x {          // 2
			x = 1;         // 3
			y = 2;         // 4
			if y then {    // 5
				call q;}   // 6
			else {            
				call r;}}} // 7

	procedure q {
		x = 1;             // 8
		call r}            // 9

	procedure r {
		x = y;             // 10
		if x then {        // 11
			x = 1;}        // 12
		else {
			y = 1;}        // 13
		z = 1;             // 14
	}
	*/

	
	/*
	container stmt:
	- while - 2
	- if - 5, 11
	
	CommonIfMatrix 
	---2  5 11 ---
	2--0  0  0 ---
	5--0  5  0 ---
	11-0  0 11 ---

	CommonWhileMatrix 
	---2  5 11 ---
	2--2  2  0 ---
	5--2  2  0 ---
	11-0  0  0 ---
	*/

	int numContainer = 3;
	int containerArray[] = {2, 5, 11};
	int ifMatrixArray[][MAX_CONTAINER] = {{0, 0, 0}, {0, 5, 0}, {0, 0, 11}};
	int whileMatrixArray[][MAX_CONTAINER] = {{2, 2, 0}, {2, 2, 0}, {0}};

	cout.flush();
	cout << "Setting up Env1 for DE InegrationTest:..." << endl;
	pkb = new PKB();
	de = new DesignExtractor(pkb);

	pkb->insertProc("p");
	pkb->insertProcStartEnd(1, 1, 7);
	pkb->insertProc("q");
	pkb->insertProcStartEnd(2, 8, 9);
	pkb->insertProc("r");
	pkb->insertProcStartEnd(3, 10, 14);

	pkb->insertLineEntity(1, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(2, Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(3, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(4, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(5, Type::Entity::IF_LINE_ENTITY);
	pkb->insertLineEntity(6, Type::Entity::CALL_LINE_ENTITY);
	pkb->insertLineEntity(7, Type::Entity::CALL_LINE_ENTITY);
	pkb->insertLineEntity(8, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(9, Type::Entity::CALL_LINE_ENTITY);
	pkb->insertLineEntity(10, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(11, Type::Entity::IF_LINE_ENTITY);
	pkb->insertLineEntity(12, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(13, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(14, Type::Entity::ASSIGNMENT_LINE_ENTITY);

	pkb->insertConstant(3, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->insertConstant(4, Type::Entity::ASSIGNMENT_LINE_ENTITY, 2);
	pkb->insertConstant(8, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->insertConstant(12, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->insertConstant(13, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->insertConstant(14, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);

	pkb->insertVar("x");
	pkb->insertVar("y");
	pkb->insertVar("z");

	pkb->setLineModifies(1, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(2, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineModifies(2, Type::Entity::WHILE_LINE_ENTITY, 2);
	pkb->setLineModifies(3, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(4, Type::Entity::ASSIGNMENT_LINE_ENTITY, 2);
	pkb->setLineModifies(8, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(10, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(11, Type::Entity::IF_LINE_ENTITY, 1);
	pkb->setLineModifies(11, Type::Entity::IF_LINE_ENTITY, 2);
	pkb->setLineModifies(12, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(13, Type::Entity::ASSIGNMENT_LINE_ENTITY, 2);
	pkb->setLineModifies(14, Type::Entity::ASSIGNMENT_LINE_ENTITY, 3);

	pkb->setProcModifies(1, 1);
	pkb->setProcModifies(1, 2);
	pkb->setProcModifies(2, 1);
	pkb->setProcModifies(3, 1);
	pkb->setProcModifies(3, 2);
	pkb->setProcModifies(3, 3);
	pkb->setProcModifies(4, 1);

	pkb->setLineUses(1, Type::Entity::ASSIGNMENT_LINE_ENTITY, 2);
	pkb->setLineUses(2, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineUses(2, Type::Entity::WHILE_LINE_ENTITY, 2);
	pkb->setLineUses(5, Type::Entity::IF_LINE_ENTITY, 2);
	pkb->setLineUses(10, Type::Entity::ASSIGNMENT_LINE_ENTITY, 2);
	pkb->setLineUses(11, Type::Entity::IF_LINE_ENTITY, 1);

	pkb->setProcUses(1, 2);
	pkb->setProcUses(1, 1);
	pkb->setProcUses(3, 2);
	pkb->setProcUses(3, 1);

	pkb->setCalls(1, 6, 2);
	pkb->setCalls(1, 7, 3);
	pkb->setCalls(2, 9, 3);

	pkb->setParent(2, 3);
	pkb->setParent(2, 4);
	pkb->setParent(2, 5);
	pkb->setParent(5, 6);
	pkb->setParent(5, 7);
	pkb->setParent(11, 12);
	pkb->setParent(11, 13);

	pkb->setFollows(1, 2);
	pkb->setFollows(3, 4);
	pkb->setFollows(4, 5);
	pkb->setFollows(8, 9);
	pkb->setFollows(10, 11);
	pkb->setFollows(11, 14);

	pkb->setCommon(Type::Entity::WHILE_LINE_ENTITY, prepareCommMatrixFromArray(ifMatrixArray, containerArray, numContainer));
	pkb->setCommon(Type::Entity::WHILE_LINE_ENTITY, prepareCommMatrixFromArray(whileMatrixArray, containerArray, numContainer));

	CPPUNIT_ASSERT_EQUAL(false, pkb->isNextStar(12, 1));
	CPPUNIT_ASSERT_EQUAL(false, pkb->isNextStar(6, 1));
	CPPUNIT_ASSERT_EQUAL(true, pkb->isNextStar(6, 3));

	//de->run();

}

void DesignExtractorWithPKBTest::createEnv2() {
	/* Environment 2
	procedure fifth5 {
		dog1 = cat2;						//1
		while dog1 {                		//2
			dog1 = bird3;          		//3
			while dog1 {           		//4
				dog1 = fish4; 			//5
				while dog1{				//6
					dog1 = can3;			//7
					while dog1{			//8
						dog1 = bird 2;	//9
					}
				}
			}
		} 
		while dog1 {                		//10
			dog1 = bird3;          		//11
			while dog1 {           		//12
				dog1 = fish4; 			//13
				while dog1{				//14
					dog1 = can3;			//15
					while dog1{			//16
						dog1 = bird 2;	//17
					}
				}
				while dog1{				//18
					dog1 = can3;			//19
					while dog1{			//20
						dog1 = bird 2;	//21
						if dog1 then{		//22
							dog1 = can3;	//23
						} else {
							dog1 = bird2;	//24
							if dog1 then {	//25
								dog1 = fish4	//26
							} else {
								dog1 = bird3;	//27
							}
						}
					}
				}
			}
		} 
		if dog1 then {							//28
			bird3 = bird2 ;						//29
		} else {
			while dog1 {							//30
				fish4 = bird2;					//31
			}
		}
		cat2 = can3;								//32
	}
	*/

	/*
		container stmt:
		- while - 2, 4

		CommonIfMatrix 
		---2  4 ---
		2--0  0 ---
		4--0  0  ---

		CommonWhileMatrix 
		---2  4 ---
		2--2  2 ---
		4--2  4 ---

	*/
	int numContainer = 2;
	int containerArray[] = {2, 4};
	int ifMatrixArray[][MAX_CONTAINER] = {{0}, {0}};
	int whileMatrixArray[][MAX_CONTAINER] = {{2, 2}, {2, 4}};


	cout.flush();
	cout << "Setting up Env2 for DE InegrationTest:..." << endl;
	pkb = new PKB();
	de = new DesignExtractor(pkb);

	pkb->insertProc("fifth5");
	pkb->insertProcStartEnd(1, 1, 32);

	pkb->insertLineEntity(1, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(2, Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(3, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(4, Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(5, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(6, Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(7, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(8, Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(9, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	
	pkb->insertLineEntity(10, Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(11, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(12, Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(13, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(14, Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(15, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(16, Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(17, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(18, Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(19, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(20, Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(21, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(22, Type::Entity::IF_LINE_ENTITY);
	pkb->insertLineEntity(23, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(24, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(25, Type::Entity::IF_LINE_ENTITY);
	pkb->insertLineEntity(26, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(27, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(28, Type::Entity::IF_LINE_ENTITY);
	pkb->insertLineEntity(29, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(30, Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(31, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(32, Type::Entity::ASSIGNMENT_LINE_ENTITY);

	pkb->insertVar("dog1");
	pkb->insertVar("cat2");
	pkb->insertVar("bird3");
	pkb->insertVar("fish4");
	pkb->insertVar("can3");
	pkb->insertVar("bird2");

	pkb->setLineModifies(1, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(2, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineModifies(3, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(4, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineModifies(5, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(6, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineModifies(7, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(8, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineModifies(9, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	
	pkb->setLineModifies(10, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineModifies(11, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(12, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineModifies(13, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(14, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineModifies(15, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(16, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineModifies(17, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(18, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineModifies(19, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(20, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineModifies(21, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(22, Type::Entity::IF_LINE_ENTITY, 1);
	pkb->setLineModifies(23, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(24, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(25, Type::Entity::IF_LINE_ENTITY, 1);
	pkb->setLineModifies(26, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(27, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(28, Type::Entity::IF_LINE_ENTITY, 3);
	pkb->setLineModifies(28, Type::Entity::IF_LINE_ENTITY, 4);
	pkb->setLineModifies(29, Type::Entity::ASSIGNMENT_LINE_ENTITY, 3);
	pkb->setLineModifies(30, Type::Entity::WHILE_LINE_ENTITY, 4);
	pkb->setLineModifies(31, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineModifies(32, Type::Entity::ASSIGNMENT_LINE_ENTITY, 2);

	pkb->setProcModifies(1, 1);
	pkb->setProcModifies(1, 2);
	pkb->setProcModifies(1, 3);
	pkb->setProcModifies(1, 4);


	pkb->setLineUses(1, Type::Entity::ASSIGNMENT_LINE_ENTITY, 2);
	pkb->setLineUses(2, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineUses(2, Type::Entity::WHILE_LINE_ENTITY, 3);
	pkb->setLineUses(2, Type::Entity::WHILE_LINE_ENTITY, 4);
	pkb->setLineUses(2, Type::Entity::WHILE_LINE_ENTITY, 5);
	pkb->setLineUses(2, Type::Entity::WHILE_LINE_ENTITY, 6);
	pkb->setLineUses(3, Type::Entity::ASSIGNMENT_LINE_ENTITY, 3);
	pkb->setLineUses(4, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineUses(4, Type::Entity::WHILE_LINE_ENTITY, 4);
	pkb->setLineUses(4, Type::Entity::WHILE_LINE_ENTITY, 5);
	pkb->setLineUses(4, Type::Entity::WHILE_LINE_ENTITY, 6);
	pkb->setLineUses(5, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineUses(6, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineUses(6, Type::Entity::WHILE_LINE_ENTITY, 5);
	pkb->setLineUses(6, Type::Entity::WHILE_LINE_ENTITY, 6);
	pkb->setLineUses(7, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);
	pkb->setLineUses(8, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineUses(8, Type::Entity::WHILE_LINE_ENTITY, 6);
	pkb->setLineUses(9, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);

	pkb->setLineUses(10, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineUses(10, Type::Entity::WHILE_LINE_ENTITY, 3);
	pkb->setLineUses(10, Type::Entity::WHILE_LINE_ENTITY, 4);
	pkb->setLineUses(10, Type::Entity::WHILE_LINE_ENTITY, 5);
	pkb->setLineUses(10, Type::Entity::WHILE_LINE_ENTITY, 6);
	pkb->setLineUses(11, Type::Entity::ASSIGNMENT_LINE_ENTITY, 3);
	pkb->setLineUses(12, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineUses(12, Type::Entity::WHILE_LINE_ENTITY, 4);
	pkb->setLineUses(12, Type::Entity::WHILE_LINE_ENTITY, 5);
	pkb->setLineUses(12, Type::Entity::WHILE_LINE_ENTITY, 6);
	pkb->setLineUses(13, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineUses(14, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineUses(14, Type::Entity::WHILE_LINE_ENTITY, 5);
	pkb->setLineUses(14, Type::Entity::WHILE_LINE_ENTITY, 6);
	pkb->setLineUses(15, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);
	pkb->setLineUses(16, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineUses(16, Type::Entity::WHILE_LINE_ENTITY, 6);
	pkb->setLineUses(17, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);
	pkb->setLineUses(18, Type::Entity::ASSIGNMENT_LINE_ENTITY, 3);
	pkb->setLineUses(18, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineUses(18, Type::Entity::ASSIGNMENT_LINE_ENTITY, 5);
	pkb->setLineUses(18, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);
	pkb->setLineUses(19, Type::Entity::ASSIGNMENT_LINE_ENTITY, 5);
	pkb->setLineUses(20, Type::Entity::ASSIGNMENT_LINE_ENTITY, 3);
	pkb->setLineUses(20, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineUses(20, Type::Entity::ASSIGNMENT_LINE_ENTITY, 5);
	pkb->setLineUses(20, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);
	pkb->setLineUses(21, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);
	pkb->setLineUses(22, Type::Entity::ASSIGNMENT_LINE_ENTITY, 3);
	pkb->setLineUses(22, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineUses(22, Type::Entity::ASSIGNMENT_LINE_ENTITY, 5);
	pkb->setLineUses(22, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);
	pkb->setLineUses(23, Type::Entity::ASSIGNMENT_LINE_ENTITY, 5);
	pkb->setLineUses(24, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);
	pkb->setLineUses(25, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineUses(25, Type::Entity::ASSIGNMENT_LINE_ENTITY, 3);
	pkb->setLineUses(26, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineUses(27, Type::Entity::ASSIGNMENT_LINE_ENTITY, 3);

	pkb->setLineUses(28, Type::Entity::IF_LINE_ENTITY, 1);
	pkb->setLineUses(28, Type::Entity::IF_LINE_ENTITY, 6);
	pkb->setLineUses(29, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);
	pkb->setLineUses(30, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineUses(30, Type::Entity::WHILE_LINE_ENTITY, 6);
	pkb->setLineUses(31, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);
	pkb->setLineUses(32, Type::Entity::ASSIGNMENT_LINE_ENTITY, 5);

	pkb->setProcUses(1, 1);
	pkb->setProcUses(1, 2);
	pkb->setProcUses(1, 3);
	pkb->setProcUses(1, 4);
	pkb->setProcUses(1, 5);
	pkb->setProcUses(1, 6);

	pkb->setParent(2, 3);
	pkb->setParent(2, 4);
	pkb->setParent(4, 5);
	pkb->setParent(4, 6);
	pkb->setParent(6, 7);
	pkb->setParent(6, 8);
	pkb->setParent(8, 9);

	pkb->setParent(10, 11);
	pkb->setParent(10, 12);
	pkb->setParent(12, 13);
	pkb->setParent(12, 14);
	pkb->setParent(12, 18);
	pkb->setParent(14, 15);
	pkb->setParent(14, 16);
	pkb->setParent(16, 17);
	pkb->setParent(18, 19);
	pkb->setParent(18, 20);
	pkb->setParent(20, 21);
	pkb->setParent(20, 22);
	pkb->setParent(22, 23);
	pkb->setParent(22, 24);
	pkb->setParent(22, 25);
	pkb->setParent(25, 26);
	pkb->setParent(25, 27);

	pkb->setParent(28, 29);
	pkb->setParent(28, 30);
	pkb->setParent(30, 31);

	pkb->setFollows(1, 2);
	pkb->setFollows(2, 10);
	pkb->setFollows(3, 4);
	pkb->setFollows(5, 6);
	pkb->setFollows(7, 8);
	pkb->setFollows(11, 12);
	pkb->setFollows(13, 14);
	pkb->setFollows(14, 18);
	pkb->setFollows(15, 16);
	pkb->setFollows(19, 20);
	pkb->setFollows(21, 22);
	pkb->setFollows(24, 25);

	pkb->setFollows(10, 28);
	pkb->setFollows(28, 32);


	//pkb->setCommon(Type::Entity::WHILE_LINE_ENTITY, prepareCommMatrixFromArray(ifMatrixArray, containerArray, numContainer));
	//pkb->setCommon(Type::Entity::WHILE_LINE_ENTITY, prepareCommMatrixFromArray(whileMatrixArray, containerArray, numContainer));

	de->run();
}

void DesignExtractorWithPKBTest::createEnv3() {
	cout.flush();
	cout << "Setting up Env3 for DE InegrationTest:..." << endl;
	pkb = new PKB();
	de = new DesignExtractor(pkb);

	pkb->insertProc("ifsource");
	pkb->insertProcStartEnd(1, 1, 8);
	pkb->insertProc("whileif");
	pkb->insertProcStartEnd(2, 9, 14);

	pkb->insertLineEntity(1, Type::Entity::IF_LINE_ENTITY);
	pkb->insertLineEntity(2, Type::Entity::IF_LINE_ENTITY);
	pkb->insertLineEntity(3, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(4, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(5, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(6, Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(7, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(8, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(9, Type::Entity::IF_LINE_ENTITY);
	pkb->insertLineEntity(10, Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(11, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(12, Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(13, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(14, Type::Entity::ASSIGNMENT_LINE_ENTITY);

	pkb->insertVar("w");
	pkb->insertVar("x");
	pkb->insertVar("y");
	pkb->insertVar("z");

	pkb->setLineModifies(1, Type::Entity::IF_LINE_ENTITY, 1);
	pkb->setLineModifies(1, Type::Entity::IF_LINE_ENTITY, 2);
	pkb->setLineModifies(1, Type::Entity::IF_LINE_ENTITY, 3);
	pkb->setLineModifies(2, Type::Entity::IF_LINE_ENTITY, 1);
	pkb->setLineModifies(2, Type::Entity::IF_LINE_ENTITY, 2);
	pkb->setLineModifies(2, Type::Entity::IF_LINE_ENTITY, 3);
	pkb->setLineModifies(3, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(4, Type::Entity::ASSIGNMENT_LINE_ENTITY, 2);
	pkb->setLineModifies(5, Type::Entity::ASSIGNMENT_LINE_ENTITY, 3);
	pkb->setLineModifies(6, Type::Entity::WHILE_LINE_ENTITY, 4);
	pkb->setLineModifies(7, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineModifies(8, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(9, Type::Entity::IF_LINE_ENTITY, 1);
	pkb->setLineModifies(9, Type::Entity::IF_LINE_ENTITY, 2);
	pkb->setLineModifies(10, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineModifies(11, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(12, Type::Entity::WHILE_LINE_ENTITY, 2);
	pkb->setLineModifies(13, Type::Entity::ASSIGNMENT_LINE_ENTITY, 2);
	pkb->setLineModifies(14, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);


	pkb->setProcModifies(1, 1);
	pkb->setProcModifies(1, 2);
	pkb->setProcModifies(1, 3);
	pkb->setProcModifies(1, 4);
	pkb->setProcModifies(2, 1);
	pkb->setProcModifies(2, 2);

	pkb->setLineUses(1, Type::Entity::IF_LINE_ENTITY, 1);
	pkb->setLineUses(1, Type::Entity::IF_LINE_ENTITY, 2);
	pkb->setLineUses(2, Type::Entity::IF_LINE_ENTITY, 2);
	pkb->setLineUses(6, Type::Entity::WHILE_LINE_ENTITY, 4);
	pkb->setLineUses(9, Type::Entity::IF_LINE_ENTITY, 1);
	pkb->setLineUses(9, Type::Entity::IF_LINE_ENTITY, 2);
	pkb->setLineUses(10, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineUses(12, Type::Entity::WHILE_LINE_ENTITY, 2);

	pkb->setProcUses(1, 1);
	pkb->setProcUses(1, 2);
	pkb->setProcUses(1, 4);
	pkb->setProcUses(2, 1);
	pkb->setProcUses(2, 2);

	pkb->setParent(1, 2);
	pkb->setParent(2, 3);
	pkb->setParent(2, 4);
	pkb->setParent(1, 5);
	pkb->setParent(6, 7);
	pkb->setParent(9, 10);
	pkb->setParent(10, 11);
	pkb->setParent(9, 12);
	pkb->setParent(12, 13);

	pkb->setFollows(1, 6);
	pkb->setFollows(6, 8);
	pkb->setFollows(9, 14);
}

void DesignExtractorWithPKBTest::createEnv4() {
		/*
	procedure Fern {
		y = 10;				// 1
		x = y + 5;			// 2
		z = x * y + 4;		// 3
		v = x + z * 12;		// 4
		call Tulip;			// 5
		v = v + y + x;		// 6
		call Lily;			// 7
		t = v + y * x;		// 8
		while idx {				// 9
			t = x - z;			// 10
			if y then {			// 11
				z = z + y;		// 12
				idx = z + 1; }	// 13
			else {	
				x = z + y;			// 14 
				call Lily;			// 15
				idx = idx - 16; }	//16
			x = z + y; }		// 17
		call Orchid; }			// 18

	procedure Orchid {
		while idx {				// 19
			y = z*3 + 2*x;		// 20
			call Tulip;			// 21
			idx = idx - 1; }	// 22
		z = z + y + idx; }		// 23

	procedure Lily {
		while v {				// 24
			y = x + y; }		// 25
		x = y + x; }			// 26

	procedure Tulip {
		while t {				// 27
			if idx then {		// 28
				x = y + 80; }	// 29
			else {
				y = y * x + z + t * v; } } }	// 30
	*/

	/*
	container stmt:
	-- if --11, 28
	-- while -- 9, 19, 24, 27
	CommonIfMatrix 
	---9  11 19 24 27 28 ---
	9--0  0  0  0  0  0  ---
	11-0  11 0  0  0  0  --- 
	19-0  0  0  0  0  0  ---
	24-0  0  0  0  0  0  ---
	27-0  0  0  0  0  0  ---
	28-0  0  0  0  0  28 ---

	CommonWhileMatrix 
	---9  11 19 24 27 28 ---
	9--9  9  0  0  0  0  ---
	11-9  9  0  0  0  0  --- 
	19-0  0  19 0  0  0  ---
	24-0  0  0  24 0  0  ---
	27-0  0  0  0 27 27  ---
	28-0  0  0  0 27 27  ---
	*/

	
	int numContainer = 6;
	int containerArray[] = {9, 11, 19, 24, 27, 28};
	int ifMatrixArray[][MAX_CONTAINER] = {{0}, {0, 11, 0}, {0}, {0}, {0}, {0, 28}};
	int whileMatrixArray[][MAX_CONTAINER] = {{9, 9, 0}, {9, 9, 0}, {0, 0, 19, 0}, 
											 {0, 0, 0, 24, 0}, {0, 0, 0, 0, 27, 27}, {0, 0, 0, 0, 27, 27}};

	cout.flush();
	cout << "Setting up Env4 for DE InegrationTest:..." << endl;
	pkb = new PKB();
	de = new DesignExtractor(pkb);

	pkb->insertProc("Fern");
	pkb->insertProcStartEnd(1, 1, 18);
	pkb->insertProc("Orchid");
	pkb->insertProcStartEnd(2, 19, 23);
	pkb->insertProc("Lily");
	pkb->insertProcStartEnd(3, 24, 26);
	pkb->insertProc("Tulip");
	pkb->insertProcStartEnd(4, 27, 30);

	pkb->insertLineEntity(1, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(2, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(3, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(4, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(5, Type::Entity::CALL_LINE_ENTITY);
	pkb->insertLineEntity(6, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(7, Type::Entity::CALL_LINE_ENTITY);
	pkb->insertLineEntity(8, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(9, Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(10, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(11, Type::Entity::IF_LINE_ENTITY);
	pkb->insertLineEntity(12, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(13, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(14, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(15, Type::Entity::CALL_LINE_ENTITY);
	pkb->insertLineEntity(16, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(17, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(18, Type::Entity::CALL_LINE_ENTITY);
	pkb->insertLineEntity(19, Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(20, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(21, Type::Entity::CALL_LINE_ENTITY);
	pkb->insertLineEntity(22, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(23, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(24, Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(25, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(26, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(27, Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(28, Type::Entity::IF_LINE_ENTITY);
	pkb->insertLineEntity(29, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(30, Type::Entity::ASSIGNMENT_LINE_ENTITY);

	pkb->insertVar("idx");  // 1
	pkb->insertVar("t");	// 2
	pkb->insertVar("v");	// 3
	pkb->insertVar("x");	// 4
	pkb->insertVar("y");	// 5
	pkb->insertVar("z");	// 6

	pkb->setLineModifies(1, Type::Entity::ASSIGNMENT_LINE_ENTITY, 5);
	pkb->setLineModifies(2, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineModifies(3, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);
	pkb->setLineModifies(4, Type::Entity::ASSIGNMENT_LINE_ENTITY, 3);
	pkb->setLineModifies(6, Type::Entity::ASSIGNMENT_LINE_ENTITY, 3);
	pkb->setLineModifies(8, Type::Entity::ASSIGNMENT_LINE_ENTITY, 2);
	pkb->setLineModifies(9, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineModifies(9, Type::Entity::WHILE_LINE_ENTITY, 2);
	pkb->setLineModifies(9, Type::Entity::WHILE_LINE_ENTITY, 4);
	pkb->setLineModifies(9, Type::Entity::WHILE_LINE_ENTITY, 6);
	pkb->setLineModifies(10, Type::Entity::ASSIGNMENT_LINE_ENTITY, 2);
	pkb->setLineModifies(11, Type::Entity::IF_LINE_ENTITY, 1);
	pkb->setLineModifies(11, Type::Entity::IF_LINE_ENTITY, 4);
	pkb->setLineModifies(11, Type::Entity::IF_LINE_ENTITY, 6);
	pkb->setLineModifies(12, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);
	pkb->setLineModifies(13, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(14, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineModifies(16, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(17, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineModifies(19, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineModifies(19, Type::Entity::WHILE_LINE_ENTITY, 5);
	pkb->setLineModifies(20, Type::Entity::ASSIGNMENT_LINE_ENTITY, 5);
	pkb->setLineModifies(22, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(23, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);
	pkb->setLineModifies(24, Type::Entity::WHILE_LINE_ENTITY, 4);
	pkb->setLineModifies(24, Type::Entity::WHILE_LINE_ENTITY, 5);
	pkb->setLineModifies(25, Type::Entity::ASSIGNMENT_LINE_ENTITY, 5);
	pkb->setLineModifies(26, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineModifies(27, Type::Entity::WHILE_LINE_ENTITY, 4);
	pkb->setLineModifies(27, Type::Entity::WHILE_LINE_ENTITY, 5);
	pkb->setLineModifies(28, Type::Entity::IF_LINE_ENTITY, 4);
	pkb->setLineModifies(28, Type::Entity::IF_LINE_ENTITY, 5);
	pkb->setLineModifies(29, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineModifies(30, Type::Entity::ASSIGNMENT_LINE_ENTITY, 5);

	pkb->setProcModifies(1, 1);
	pkb->setProcModifies(1, 2);
	pkb->setProcModifies(1, 3);
	pkb->setProcModifies(1, 4);
	pkb->setProcModifies(1, 5);
	pkb->setProcModifies(1, 6);
	pkb->setProcModifies(2, 1);
	pkb->setProcModifies(2, 5);
	pkb->setProcModifies(2, 6);
	pkb->setProcModifies(3, 4);
	pkb->setProcModifies(3, 5);
	pkb->setProcModifies(4, 4);
	pkb->setProcModifies(4, 5);

	pkb->setLineUses(2, Type::Entity::ASSIGNMENT_LINE_ENTITY, 5);
	pkb->setLineUses(3, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineUses(3, Type::Entity::ASSIGNMENT_LINE_ENTITY, 5);
	pkb->setLineUses(4, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineUses(4, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);
	pkb->setLineUses(6, Type::Entity::ASSIGNMENT_LINE_ENTITY, 3);
	pkb->setLineUses(6, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineUses(6, Type::Entity::ASSIGNMENT_LINE_ENTITY, 5);
	pkb->setLineUses(8, Type::Entity::ASSIGNMENT_LINE_ENTITY, 3);
	pkb->setLineUses(8, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineUses(8, Type::Entity::ASSIGNMENT_LINE_ENTITY, 5);
	pkb->setLineUses(9, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineUses(9, Type::Entity::WHILE_LINE_ENTITY, 4);
	pkb->setLineUses(9, Type::Entity::WHILE_LINE_ENTITY, 5);
	pkb->setLineUses(9, Type::Entity::WHILE_LINE_ENTITY, 6);
	pkb->setLineUses(10, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineUses(10, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);
	pkb->setLineUses(11, Type::Entity::IF_LINE_ENTITY, 1);
	pkb->setLineUses(11, Type::Entity::IF_LINE_ENTITY, 5);
	pkb->setLineUses(11, Type::Entity::IF_LINE_ENTITY, 6);
	pkb->setLineUses(12, Type::Entity::ASSIGNMENT_LINE_ENTITY, 5);
	pkb->setLineUses(12, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);
	pkb->setLineUses(13, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);
	pkb->setLineUses(14, Type::Entity::ASSIGNMENT_LINE_ENTITY, 5);
	pkb->setLineUses(14, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);
	pkb->setLineUses(16, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineUses(17, Type::Entity::ASSIGNMENT_LINE_ENTITY, 5);
	pkb->setLineUses(17, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);
	pkb->setLineUses(19, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineUses(19, Type::Entity::WHILE_LINE_ENTITY, 4);
	pkb->setLineUses(19, Type::Entity::WHILE_LINE_ENTITY, 6);
	pkb->setLineUses(20, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineUses(20, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);
	pkb->setLineUses(22, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineUses(23, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineUses(23, Type::Entity::ASSIGNMENT_LINE_ENTITY, 5);
	pkb->setLineUses(23, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);
	pkb->setLineUses(27, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineUses(27, Type::Entity::WHILE_LINE_ENTITY, 2);
	pkb->setLineUses(27, Type::Entity::WHILE_LINE_ENTITY, 3);
	pkb->setLineUses(27, Type::Entity::WHILE_LINE_ENTITY, 4);
	pkb->setLineUses(27, Type::Entity::WHILE_LINE_ENTITY, 5);
	pkb->setLineUses(27, Type::Entity::WHILE_LINE_ENTITY, 6);
	pkb->setLineUses(28, Type::Entity::IF_LINE_ENTITY, 1);
	pkb->setLineUses(28, Type::Entity::IF_LINE_ENTITY, 2);
	pkb->setLineUses(28, Type::Entity::IF_LINE_ENTITY, 3);
	pkb->setLineUses(28, Type::Entity::IF_LINE_ENTITY, 4);
	pkb->setLineUses(28, Type::Entity::IF_LINE_ENTITY, 5);
	pkb->setLineUses(28, Type::Entity::IF_LINE_ENTITY, 6);
	pkb->setLineUses(29, Type::Entity::ASSIGNMENT_LINE_ENTITY, 5);
	pkb->setLineUses(30, Type::Entity::ASSIGNMENT_LINE_ENTITY, 2);
	pkb->setLineUses(30, Type::Entity::ASSIGNMENT_LINE_ENTITY, 3);
	pkb->setLineUses(30, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineUses(30, Type::Entity::ASSIGNMENT_LINE_ENTITY, 5);
	pkb->setLineUses(30, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);

	pkb->setProcUses(1, 1);
	pkb->setProcUses(1, 2);
	pkb->setProcUses(1, 3);
	pkb->setProcUses(1, 4);
	pkb->setProcUses(1, 5);
	pkb->setProcUses(1, 6);
	pkb->setProcUses(2, 1);
	pkb->setProcUses(2, 4);
	pkb->setProcUses(2, 5);
	pkb->setProcUses(2, 6);
	pkb->setProcUses(3, 3);
	pkb->setProcUses(3, 4);
	pkb->setProcUses(3, 5);
	pkb->setProcUses(4, 1);
	pkb->setProcUses(4, 2);
	pkb->setProcUses(4, 3);
	pkb->setProcUses(4, 4);
	pkb->setProcUses(4, 5);
	pkb->setProcUses(4, 6);

	pkb->setParent(9, 10);
	pkb->setParent(9, 11);
	pkb->setParent(9, 17);
	pkb->setParent(11, 12);
	pkb->setParent(11, 13);
	pkb->setParent(11, 14);
	pkb->setParent(11, 15);
	pkb->setParent(11, 16);
	pkb->setParent(19, 20);
	pkb->setParent(19, 21);
	pkb->setParent(19, 22);
	pkb->setParent(24, 25);
	pkb->setParent(27, 28);
	pkb->setParent(28, 29);
	pkb->setParent(28, 30);

	pkb->setFollows(1, 2);
	pkb->setFollows(2, 3);
	pkb->setFollows(3, 4);
	pkb->setFollows(4, 5);
	pkb->setFollows(5, 6);
	pkb->setFollows(6, 7);
	pkb->setFollows(7, 8);
	pkb->setFollows(8, 9);
	pkb->setFollows(9, 18);
	pkb->setFollows(10, 11);
	pkb->setFollows(11, 17);
	pkb->setFollows(12, 13);
	pkb->setFollows(14, 15);
	pkb->setFollows(15, 16);
	pkb->setFollows(19, 23);
	pkb->setFollows(20, 21);
	pkb->setFollows(21, 22);
	pkb->setFollows(24, 26);

	pkb->setCalls(1, 5, 4);
	pkb->setCalls(1, 7, 3);
	pkb->setCalls(1, 15, 3);
	pkb->setCalls(1, 18, 2);
	pkb->setCalls(2, 21, 4);

	pkb->setCommon(Type::Entity::WHILE_LINE_ENTITY, prepareCommMatrixFromArray(ifMatrixArray, containerArray, numContainer));
	pkb->setCommon(Type::Entity::WHILE_LINE_ENTITY, prepareCommMatrixFromArray(whileMatrixArray, containerArray, numContainer));


	de->run();
}

void DesignExtractorWithPKBTest::createEnv5() {
		/*
	procedure Charlie{
		i = 15;					// 1
		while i	{				// 2
			a = b;				// 3
			if x then {			// 4
				b = c;			// 5                  
				if c then {		// 6
					c = d; }	// 7
				else { 
					d = e; }}	// 8
			else{
				c = e;			// 9
			}
			while y {           // 10
				b = k; }        // 11
			b = z; }}          // 12
	*/

	/*
		container stmt:
	-- if --4, 6
	-- while -- 2, 10

		CommonIfMatrix 
		---2  4  6 10 ---
		2--0  4  6  0 ---
		4--4  4  4  0 ---
		6--6  4  6  0 ---
		10-0  0  0  0 ---

		CommonWhileMatrix 
		---2  4  6 10 ---
		2--2  2  2  2 ---
		4--2  2  2  2 ---
		6--2  2  2  2 ---
		10-2  2  2  2 ---
	*/

	int numContainer = 4;
	int containerArray[] = {2, 4, 6, 10};
	int ifMatrixArray[][MAX_CONTAINER] = {{0, 4, 6, 0}, {4, 4, 4, 0}, {6, 4, 6, 0}, {0}};
	int whileMatrixArray[][MAX_CONTAINER] = {{2, 2, 2, 2}, {2, 2, 2, 2}, 
											 {2, 2, 2, 2}, {2, 2, 2, 2}};

	cout.flush();
	cout << "Setting up Env5 for DE InegrationTest:..." << endl;
	pkb = new PKB();
	de = new DesignExtractor(pkb);

	pkb->insertProc("Charlie");
	pkb->insertProcStartEnd(1, 1, 12);

	pkb->insertLineEntity(1, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(2, Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(3, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(4, Type::Entity::IF_LINE_ENTITY);
	pkb->insertLineEntity(5, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(6, Type::Entity::IF_LINE_ENTITY);
	pkb->insertLineEntity(7, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(8, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(9, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(10, Type::Entity::WHILE_LINE_ENTITY);
	pkb->insertLineEntity(11, Type::Entity::ASSIGNMENT_LINE_ENTITY);
	pkb->insertLineEntity(12, Type::Entity::ASSIGNMENT_LINE_ENTITY);

	pkb->insertVar("a");	// 1
	pkb->insertVar("b");	// 2
	pkb->insertVar("c");	// 3
	pkb->insertVar("d");	// 4
	pkb->insertVar("e");	// 5
	pkb->insertVar("i");	// 6
	pkb->insertVar("k");	// 7
	pkb->insertVar("x");	// 8
	pkb->insertVar("y");	// 9
	pkb->insertVar("z");	// 10

	pkb->setLineModifies(1, Type::Entity::ASSIGNMENT_LINE_ENTITY, 6);
	pkb->setLineModifies(2, Type::Entity::WHILE_LINE_ENTITY, 1);
	pkb->setLineModifies(2, Type::Entity::WHILE_LINE_ENTITY, 2);
	pkb->setLineModifies(2, Type::Entity::WHILE_LINE_ENTITY, 3);
	pkb->setLineModifies(2, Type::Entity::WHILE_LINE_ENTITY, 4);
	pkb->setLineModifies(3, Type::Entity::ASSIGNMENT_LINE_ENTITY, 1);
	pkb->setLineModifies(4, Type::Entity::IF_LINE_ENTITY, 2);
	pkb->setLineModifies(4, Type::Entity::IF_LINE_ENTITY, 3);
	pkb->setLineModifies(4, Type::Entity::IF_LINE_ENTITY, 4);
	pkb->setLineModifies(5, Type::Entity::ASSIGNMENT_LINE_ENTITY, 2);
	pkb->setLineModifies(6, Type::Entity::IF_LINE_ENTITY, 3);
	pkb->setLineModifies(6, Type::Entity::IF_LINE_ENTITY, 4);
	pkb->setLineModifies(7, Type::Entity::ASSIGNMENT_LINE_ENTITY, 3);
	pkb->setLineModifies(8, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineModifies(9, Type::Entity::ASSIGNMENT_LINE_ENTITY, 3);
	pkb->setLineModifies(10, Type::Entity::WHILE_LINE_ENTITY, 2);
	pkb->setLineModifies(11, Type::Entity::ASSIGNMENT_LINE_ENTITY, 2);
	pkb->setLineModifies(12, Type::Entity::WHILE_LINE_ENTITY, 2);

	pkb->setProcModifies(1, 1);
	pkb->setProcModifies(1, 2);
	pkb->setProcModifies(1, 3);
	pkb->setProcModifies(1, 4);
	pkb->setProcModifies(1, 6);

	pkb->setLineUses(2, Type::Entity::WHILE_LINE_ENTITY, 6);
	pkb->setLineUses(2, Type::Entity::WHILE_LINE_ENTITY, 2);
	pkb->setLineUses(2, Type::Entity::WHILE_LINE_ENTITY, 8);
	pkb->setLineUses(2, Type::Entity::WHILE_LINE_ENTITY, 3);
	pkb->setLineUses(2, Type::Entity::WHILE_LINE_ENTITY, 4);
	pkb->setLineUses(2, Type::Entity::WHILE_LINE_ENTITY, 5);
	pkb->setLineUses(3, Type::Entity::ASSIGNMENT_LINE_ENTITY, 2);
	pkb->setLineUses(4, Type::Entity::IF_LINE_ENTITY, 8);
	pkb->setLineUses(4, Type::Entity::IF_LINE_ENTITY, 3);
	pkb->setLineUses(4, Type::Entity::IF_LINE_ENTITY, 4);
	pkb->setLineUses(4, Type::Entity::IF_LINE_ENTITY, 5);
	pkb->setLineUses(5, Type::Entity::ASSIGNMENT_LINE_ENTITY, 3);
	pkb->setLineUses(6, Type::Entity::IF_LINE_ENTITY, 3);
	pkb->setLineUses(6, Type::Entity::IF_LINE_ENTITY, 4);
	pkb->setLineUses(6, Type::Entity::IF_LINE_ENTITY, 5);
	pkb->setLineUses(7, Type::Entity::ASSIGNMENT_LINE_ENTITY, 4);
	pkb->setLineUses(8, Type::Entity::ASSIGNMENT_LINE_ENTITY, 5);
	pkb->setLineUses(9, Type::Entity::ASSIGNMENT_LINE_ENTITY, 5);
	pkb->setLineUses(10, Type::Entity::WHILE_LINE_ENTITY, 9);
	pkb->setLineUses(10, Type::Entity::WHILE_LINE_ENTITY, 7);
	pkb->setLineUses(10, Type::Entity::WHILE_LINE_ENTITY, 10);
	pkb->setLineUses(11, Type::Entity::ASSIGNMENT_LINE_ENTITY, 7);
	pkb->setLineUses(11, Type::Entity::ASSIGNMENT_LINE_ENTITY, 10);

	pkb->setProcUses(1, 2);
	pkb->setProcUses(1, 3);
	pkb->setProcUses(1, 4);
	pkb->setProcUses(1, 5);
	pkb->setProcUses(1, 6);
	pkb->setProcUses(1, 7);
	pkb->setProcUses(1, 8);
	pkb->setProcUses(1, 9);
	pkb->setProcUses(1, 10);

	pkb->setParent(2, 3);
	pkb->setParent(2, 4);
	pkb->setParent(2, 10);
	pkb->setParent(2, 12);
	pkb->setParent(4, 5);
	pkb->setParent(4, 6);
	pkb->setParent(4, 9);
	pkb->setParent(6, 7);
	pkb->setParent(6, 8);
	pkb->setParent(10, 11);

	pkb->setFollows(1, 2);
	pkb->setFollows(3, 4);
	pkb->setFollows(5, 6);
	pkb->setFollows(4, 10);
	pkb->setFollows(10, 12);

pkb->setCommon(Type::Entity::WHILE_LINE_ENTITY, prepareCommMatrixFromArray(ifMatrixArray, containerArray, numContainer));
	pkb->setCommon(Type::Entity::WHILE_LINE_ENTITY, prepareCommMatrixFromArray(whileMatrixArray, containerArray, numContainer));

	de->run();
}

void DesignExtractorWithPKBTest::testUpdateEarliestCommonParent(){
	//createEnv1();
	//de->updateEarliestCommonParent();

	//createEnv2();
	//de->updateEarliestCommonParent();

	//createEnv4();
	//de->updateEarliestCommonParent();

	createEnv5();
	de->updateEarliestCommonParent();
}

Type::Map::ParentMatrix DesignExtractorWithPKBTest::prepareCommMatrixFromArray(int a[][MAX_CONTAINER], int index[], int size) {
	Type::Map::ParentMatrix ans;
	Type::Map::ParentMap row;
	for (int i = 0; i<size; i++) {
		row = Type::Map::ParentMap();
		for (int j = 0; j<size; j++) {
			row.insert(std::pair<Type::Index::Line, Type::Index::Line> (index[j], a[i][j]));
		}
		ans.insert(std::make_pair<Type::Index::Line, Type::Map::ParentMap> (index[i], row));
	}
	return ans;
}